# Import data
restroom_cleaned = read_csv(here::here("./Data/Public_Restrooms_20241203.csv")) %>%
janitor::clean_names()
## Rows: 1047 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): Facility Name, Location Type, Operator, Status, Open, Hours of Ope...
## dbl (2): Latitude, Longitude
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
subway_df = read_csv(here::here("./Data/NYC_Transit_Subway_Entrance_And_Exit_Data.csv")) %>%
janitor::clean_names()
## Rows: 1868 Columns: 32
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (22): Division, Line, Station Name, Route1, Route2, Route3, Route4, Rout...
## dbl (8): Station Latitude, Station Longitude, Route8, Route9, Route10, Rout...
## lgl (2): ADA, Free Crossover
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Clean restroom data
restroom_cleaned = restroom_cleaned %>%
select(
-website, -operator, -hours_of_operation
) %>%
rename(
restroom_latitude = latitude,
restroom_longitude = longitude,
restroom_location = location
) %>%
mutate(
restroom_latitude = as.numeric(restroom_latitude),
restroom_longitude = as.numeric(restroom_longitude),
restroom_location = st_as_sfc(restroom_location), #convert to point
open = factor(
open,
levels = c("Future", "Seasonal", "Year Round"),
ordered = TRUE
),
accessibility = factor(
accessibility,
levels = c("Not Accessible", "Partially Accessible", "Fully Accessible"),
ordered = TRUE
),
changing_stations = case_when(
changing_stations %in% c("Yes, in single-stall all gender restroom only",
"Yes, in women's restroom only",
"Yes") ~ 1,
changing_stations == "No" ~ 0
),
status = case_when(
status %in% c("Not Operational",
"Closed for Construction",
"Closed") ~ 0,
status == "Operational" ~ 1
)
)
# Convert dataframe to sf for spatial operations
restroom_sf = st_sf(restroom_cleaned, crs = 4326)
restroom_df = restroom_cleaned %>%
filter(location_type == 'Transit')
# Load the dataset
subway_df = read_csv(here::here("./Data/NYC_Transit_Subway_Entrance_And_Exit_Data.csv"))
## Rows: 1868 Columns: 32
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (22): Division, Line, Station Name, Route1, Route2, Route3, Route4, Rout...
## dbl (8): Station Latitude, Station Longitude, Route8, Route9, Route10, Rout...
## lgl (2): ADA, Free Crossover
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Clean the dataset
subway_cleaned = subway_df %>%
janitor::clean_names() %>%
select(
line, station_name, station_latitude, station_longitude,
route1, route2, route3, route4, route5, route6,
route7, route8, route9, route10, route11,
entry, exit_only, vending, entrance_type, ada
) %>%
mutate(across(starts_with("route"), ~ replace_na(as.character(.), ""))) %>%
mutate(
station_latitude = as.numeric(station_latitude),
station_longitude = as.numeric(station_longitude)
)
restroom_location_bar = restroom_cleaned |>
group_by(location_type) |>
count(location_type) |>
mutate(loation_type = fct_reorder(location_type, n)) |>
plot_ly (x = ~location_type, y = ~n, color = ~location_type,
type = "bar",text = ~n, textposition = "outside") |>
layout(
xaxis = list(title = "Location Type"),
yaxis = list(title = "Number of Restrooms")
)
restroom_location_bar
The majority of collected restrooms are located in Park and Library, and only a few restrooms are located in Privately Owned Public Space, Public Plaze, and Transit. This might provide guidance for the future establishment of public restrooms: public plaza have siginificant foot traffic, yet public restrooms are so scarce.
restroom_open_bar = restroom_cleaned |>
filter(!is.na(open))|>
group_by(open) |>
count(open, name = "n") |>
ungroup()|>
mutate(open = fct_reorder(open, n)) |>
plot_ly (x = ~open, y = ~n, color = ~open,
type = "bar", text = ~n, textposition = "outside",
texttemplate = "%{text}") |>
layout(
xaxis = list(title = "Open Type"),
yaxis = list(title = "Number of Restrooms")
)
restroom_open_bar
From the collected data, New York City provides public restroom facilities as follows, 864 open Year Round, 123 open Seasonal, and 12 open Future. Most public restrooms are open year-round, which is good news!
restroom_accessibility_bar = restroom_cleaned |>
filter(!is.na(accessibility))|>
group_by(accessibility) |>
count(accessibility, name = "n") |>
ungroup()|>
mutate(accessibility = fct_reorder(accessibility, n)) |>
plot_ly (x = ~accessibility, y = ~n, color = ~accessibility,
type = "bar",text = ~n, textposition = "outside") |>
layout(
xaxis = list(title = "Accessibility Type"),
yaxis = list(title = "Number of Restrooms")
)
restroom_accessibility_bar
Although the number of Fully Accessible is the highest, there are still quite a few that are Not Accessible. We still need to work on improving the implementation of public restrooms to provide services for everyone.
restroom_type_bar = restroom_cleaned |>
filter(!is.na(restroom_type))|>
group_by(restroom_type) |>
count(restroom_type, name = "n") |>
ungroup()|>
mutate(restroom_type = fct_reorder(restroom_type, n)) |>
plot_ly (x = ~restroom_type, y = ~n, color = ~restroom_type,
type = "bar", text = ~n, textposition = "outside") |>
layout(
xaxis = list(title = "Restroom Type"),
yaxis = list(title = "Number of Restrooms")
)
restroom_type_bar
Multi-Stall W/M Restrooms are the most commonly built, while Multi-Stall All Gender Restrooms are the least, with only 4. We need to provide more Multi-Stall All Gender Restrooms so they can serve all groups and more people at same time.
subway_vending_pie = subway_cleaned |>
group_by(vending) |>
count(vending, name = "n") |>
mutate(vending = fct_reorder(vending, n)) |>
plot_ly (labels = ~vending, values = ~n, type = "pie",
textinfo = "label+percent",
marker = list(colors = viridis::viridis(2)) )|>
layout(title = "Subway Vending"
)
subway_vending_pie
The pie chart tells that mostly subway stations have vending machines now.
subway_entrance_bar = subway_cleaned |>
group_by(entrance_type) |>
count(entrance_type, name = "n") |>
mutate(entrance_type = fct_reorder(entrance_type, n)) |>
plot_ly (x = ~entrance_type, y = ~n, color = ~entrance_type, colors = "viridis", text = ~n, textposition = "outside", type = "bar") |>
layout(
xaxis = list(title = "Subway Entrance Type"),
yaxis = list(title = "Number of Subway Stations")
)
subway_entrance_bar
Majority of subway stations’ entrance type is Stair. The least common subway station entrance is Walkway and Ramp.